<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>后台管理系统</title>
    <link rel="stylesheet" href="__STATIC__/common/css/login.css" />
    <script type="text/javascript" src="__STATIC__/common/js/jquery-2.1.4.min.js"></script>
    <script src="__STATIC__/layuiadmin/layui/layui.all.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#myForm").keydown(function (event) {
                if ((event.which || event.keyCode) == 13) {
                    $('.submitForm').trigger('click');
                }
            });

            $('.submitForm').click(function () {
                var myForm = $('#myForm');
                var requestParames = myForm.find('input, select, textarea').serialize();
                var url = myForm.attr('action');
                $.post(url,requestParames,function (data) {
                    if(data.code == 1){
                        layer.msg(data.msg);
                        setTimeout(function () {
                            if (data.url) {
                                location.href = '/';
                            } else {
                                location.reload();
                            }
                        }, 1500);
                    }else {
                        layer.msg(data.msg);
                        $("input[name='verify_code']").val('');
                        editVerifyCode();
                    }
                })

            });
        });

        function editVerifyCode(){
            $('#codeImg').attr("src", '{:url("Login/verifyCode")}?random=' + Math.random());
        }
    </script>
</head>

<body>
<div id="tab">
    <ul class="tab_menu">
        <li class="selected">管理员登录</li>
    </ul>
    <div class="tab_box">
        <form id="myForm" action="" method="post">
            <div>
                <label>用户名：</label>
                <input type="text" name="username" value="" placeholder="请输入用户名"/>
            </div>
            <div>
                <label>密&nbsp;&nbsp;&nbsp;码：</label>
                <input type="password" name="password" value="" placeholder="请输入密码"/>
            </div>
            <div id="code">
                <label>验证码：</label>
                <input type="text" name="verify_code" value="" placeholder="请输入验证码"/>
                <img id="codeImg" src="{:url('Login/verifyCode')}" onclick="editVerifyCode();"/>
            </div>
            <div>
                <button type="button" class="submitForm">登录</button>
            </div>
        </form>
    </div>
</div>
<div class="screenbg">
    <ul>
        <li><img width="100%" height="100%" src="__STATIC__/common/img/login-img.jpg"></li>
    </ul>
</div>
</body>
</html>
